<!DOCTYPE html>
<html lang="en">
<head>
    {{template "header" .}}
</head>
<body>
{{template "navbar" .}}
<link rel="stylesheet" href="/editor.md/css/editormd.css"/>
<form id="test-editor" method="post">
    <textarea style="display:none;">{{.Content}}</textarea>
</form>
<script src="/js/zepto.min.js"></script>
<script>
    var jQuery = Zepto;
</script>
<script src="/js/jquery.min.js"></script>
<script src="/editor.md/lib/marked.min.js"></script>
<script src="/editor.md/lib/prettify.min.js"></script>
<script src="/editor.md/lib/raphael.min.js"></script>
<script src="/editor.md/lib/underscore.min.js"></script>
<script src="/editor.md/lib/sequence-diagram.min.js"></script>
<script src="/editor.md/lib/flowchart.min.js"></script>
<script src="/editor.md/lib/jquery.flowchart.min.js"></script>
<script src="/editor.md/editormd.js"></script>
<script type="text/javascript">
    $(function () {
        var editor = editormd("test-editor", {
            height          : 800,
            htmlDecode      : "style,script,iframe",  // you can filter tags decode
            emoji           : true,
            taskList        : true,
            tocm            : true,
            tocContainer    : "",
            tocDropdown     : false,
            tex             : true,  // 默认不解析
            flowChart       : true,  // 默认不解析
            sequenceDiagram : true,  // 默认不解析
            path            : "/editor.md/lib/",
            imageUpload     : true, //开启图片上传
            imageUploadURL  : '/admin/image-paste-upload', //图片上传后台地址
            onload: function() {
                editormd.loadPlugin("/editor.md/plugins/image-handle-paste/image-handle-paste", function(){
                    editor.imagePaste();
                });
            },
            onchange:function () {
                var url = "/admin/save/{{.CurId}}"
                $.post(url, {txt: $("#test-editor textarea").text()}, function (result) {
                    if (result.code != 0) {
                        alert(result.msg)
                    }
                });
            }
        });

        // ctrl+s 自动保存
        $(document).keydown(function (event) {
            let currKey = 0, e = e || event;
            currKey = e.keyCode || e.which || e.charCode;
            if (!(String.fromCharCode(event.which).toLowerCase() == 's' && event.ctrlKey) && !(event.which == 19)) {
                return true;
            }
            event.preventDefault();
            var txt = $("#test-editor textarea").text()
            var url = "/admin/save/{{.CurId}}"
            $.post(url, {txt: txt}, function (result) {
                if (result.code != 0) {
                    alert(result.msg)
                }
            });
            return false;
        });
    });
</script>

</body>
</html>